/**
 * Copyright (C) 2024-2030 Super BilGen & 超亿时代信息技术股份有限公司.All Rights Reserved.
 */
package cn.com.yang.controller;

import java.sql.ResultSet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Model cn.com.yang.controller.TestProcdure
 * @Desc  存储过程测试
 * @author yangyijin
 * @since 2025年3月26日-下午3:17:53
 */
@RestController
public class TestProcdure {
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	/**
	 * DELIMITER $$
		CREATE DEFINER=`root`@`localhost` PROCEDURE `getAllUser`()
		BEGIN
			select * from yyj.t_users;
		END$$
		DELIMITER ;
	 * java调用存储过程
	 */
	@GetMapping("/api/getAllUser")
	public void getAllUser() {
		String sql= "{call getAllUser()}";
		jdbcTemplate.execute(sql, (PreparedStatementCallback<Void>)ps->{
			try(ResultSet res = ps.executeQuery()){
				while(res.next()) {
					System.out.println("User ID: " + res.getInt("id") + ", Name: " + res.getString("username"));
				}
			}
			return null;
		});
	}
}
